import { defineStore } from 'pinia'
import { fetchEditTopic } from '@/axios/api/topic'
export const useTopicManageStore = defineStore('topicManage', {
  state: () => ({
    isShowTopicSetting: false,
    topicSettingData: {},
  }),
  actions: {
    setTopicSettingData(data) {
      this.topicSettingData = data
    },
    hideTopicSetting() {
      this.isShowTopicSetting = false
    },
    showTopicSetting() {
      this.isShowTopicSetting = true
    },

    handleTopicNameChange(paramsValue) {
      const params = {}

      if (this.topicSettingData.label === '主题名称') {
        params.topicName = this.topicSettingData.value
      } else if (this.topicSettingData.label === '主题描述') {
        params.description = this.topicSettingData.value
      } else if (this.topicSettingData.label === '申请问题') {
        params.question = this.topicSettingData.value
        params.rest = 1
      } else if (this.topicSettingData.label === '主题头像') {
        params.coverImage = paramsValue
      } else if (this.topicSettingData.label === '主题背景') {
        params.bgImage = paramsValue
      }

      return fetchEditTopic({
        id: this.topicSettingData.topicId,
        ...params,
      })
    },
  },
})
